<div class="layui-fluid layui-anim febs-anim" id="febs-obj" lay-title="${className}管理">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="obj-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <#if columns??>
                                    <#list columns as column>
                                        <#if column.name != 'id'>
                                            <div class="layui-inline">
                                                <label class="layui-form-label layui-form-label-sm">${column.remark}</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="${column.field?uncap_first}" autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                        </#if>
                                    </#list>
                                    </#if>

                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="objTable" lay-data="{id: 'objTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="obj-option">
    <a lay-event="detail" ><i
                class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>
    <a lay-event="edit" ><i
                class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>
    <a lay-event="del" ><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#febs-obj'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns;

        form.render();

        initTable();

        laydate.render({
            elem: '#createTime',
            range: true,
            trigger: 'click'
        });

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('objTable');
                if (name === 'add') {
                    febs.modal.open('新增', '${className?uncap_first}/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '50%',
                        yes: function (index, layero) {
                            $('#obj-add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#obj-add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的记录');
                    } else {
                        febs.modal.confirm('删除', '确定删除该条记录？', function () {
                            var objIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                objIds.push(item.id)
                            });
                            deleteobjs(objIds.join(','));
                        });
                    }
                }
            },
            options: [{
                name: 'add',
                title: '新增'
            }, {
                name: 'delete',
                title: '删除'
            }]
        });


        table.on('tool(objTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                febs.modal.confirm('删除', '确定删除该条记录？', function () {
                    deleteobjs(data.id);
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改', '${className?uncap_first}/update/' + data.id, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#obj-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(objTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            tableIns.reload({where: getQueryParams(), page: {curr: 1}});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'objTable',
                url: ctx + '${className?uncap_first}/list',
                cols: [[
                    {type: 'checkbox'},
                    <#if columns??>
                    <#list columns as column>
                    <#if column.name != 'id'>
                    {field: '${column.field?uncap_first}', title: '${column.remark}'},
                    </#if>
                    </#list>
                    </#if>
                    {title: '操作', toolbar: '#obj-option', minWidth: 140}
                ]]
            });
        }

        function getQueryParams() {
            return {
                <#if columns??>
                <#list columns as column>
                <#if column.name != 'id'>
                    ${column.field?uncap_first}: $searchForm.find('input[name="${column.field?uncap_first}"]').val().trim(),
                </#if>
                </#list>
                </#if>
            };
        }

        function deleteobjs(objIds) {
            febs.get(ctx + '${className?uncap_first}/delete/' + objIds, null, function () {
                febs.alert.success('删除成功');
                $query.click();
            });
        }
    })
</script>